/**
 * 常用方法和easyui扩展
 * 
 * @author Sylthas
 */

var sys = $.extend({}, sys); /* 全局对象 */

/**
 * 项目根路径(BasePath)
 */
sys.bp = function() {
	var curWwwPath = window.document.location.href;
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
	var localhostPaht = curWwwPath.substring(0, pos);
	var projectName = pathName
			.substring(0, pathName.substr(1).indexOf('/') + 1);
	return (localhostPaht + projectName);
};

// 浏览器小于IE8
sys.isLessThanIE8 = !-[ 1, ];

/** ************************* String方法 ****************************** */
// 格式化
sys.fmts = function(s) {
	for ( var i = 0; i < arguments.length - 1; i++) {
		s = s.replace('{' + i + '}', arguments[i + 1]);
	}
	return s;
};
sys.isEmpty = function(s) {
	if (typeof s == 'string') {
		return s === '';
	}
	return typeof s == 'undefined';
};
// 去空格
sys.trim = function(s) {
	return s.replace(/(^\s*)|(\s*$)/g, "");
};
sys.ltrim = function(s) {
	return s.replace(/(^\s*)/g, "");
};
sys.rtrim = function(s) {
	return s.replace(/(\s*$)/g, "");
};

/** ************************* 操作Cookie ****************************** */
// 设置
sys.setCookie = function(k, v, d) {
	var e = new Date();
	e.setTime(e.getTime() + d * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(v) + "; expires=" + e.toGMTString();
};
// 获取
sys.getCookie = function(k) {
	var c = document.cookie;
	if (c.length) {
		var a = c.split(';');
		for ( var i = 0; i < a.length; i++) {
			var v = a[i].split('=');
			if (v[0] == k) {
				return unescape(v[1]);
			}
		}
	}
};

/** ************************** 对象继承 Object Extend Start *************** */

// 构造函数继承
sys.extend = function(child, parent) {
	var o = function() {
	};
	o.prototype = parent.prototype;
	child.prototype = new o();
	child.prototype.constructor = child;
	child.uber = parent.prototype;
};

// 非构造函数继承
// 把子对象的prototype指向父对象
sys.object = function(o) {
	function f() {
	}
	f.prototype = o;
	return new f();
};

// 浅拷贝
sys.shallowCopy = function(p) {
	var c = {};
	for ( var i in p) {
		c[i] = p[i];
	}
	c.uber = p;
	return c;
};

// 深拷贝
sys.deepCopy = function(p, c) {
	var c = c || {};
	for ( var i in p) {
		if (typeof p[i] === 'object') {
			c[i] = (p[i].constructor === Array) ? [] : {};
			// 递归拷贝
			arguments.callee(p[i], c[i]);
		} else {
			c[i] = p[i];
		}
	}
	return c;
};

/** 对象继承 Object Extend End * */

// $.cookie('easyuiThemeName', t, {expires : 7});
